\usepackage[a4paper, left = 1.5cm, right = 1.5cm, top = 3cm, bottom = 3cm]{geometry}
\usepackage{savesym}
\usepackage{float}
\usepackage[unicode,colorlinks,linkcolor=red,anchorcolor=blue,citecolor=green]{hyperref}
\usepackage{graphicx,xcolor,color}
\usepackage{titling}
\usepackage{tikz}
\usepackage{makecell} % 表格内换行
%
%配置定理环境, 用于对代码抄录环境进行编号
\usepackage{amsmath}
\usepackage{amsthm}
\newtheoremstyle{mystyle}% name of the style to be used
{0 pt}% measure of space to leave above the theorem. E.g.: 3pt
{0 pt}% measure of space to leave below the theorem. E.g.: 3pt
{\em}% name of font to use in the body of the theorem
{0pt}% measure of space to indent
{\ttfamily}% name of head font
{\newline}% punctuation between head and body
{ }% space after theorem head; " " = normal interword space
{}
\theoremstyle{definition}
\newtheorem{code_example}{代码示例}[section]

%代码抄录环境所使用的package
% 环境名为lstlisting
\usepackage{pgfplots}
\usepackage{listings}
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
% https://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings
\lstset{%
    language=C++,
    backgroundcolor=\color{white},
    %    basicstyle=\tiny,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=t,
    commentstyle=\color{mygreen},
    deletekeywords={...},
    escapeinside={\%*}{*)},
    extendedchars=true,
    frame=single,
    keepspaces=true,
    keywordstyle=\color{blue},
    language=Octave,
    %otherkeywords={*,...},
    numbers=left,
    numbersep=8pt,
    numberstyle=\small\ttfamily\color{mygray},
    rulecolor=\color{black},
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    stepnumber=1,
    stringstyle=\color{mymauve},
    tabsize=4,
    title=\lstname
}

\lstdefinestyle{customcpp}{
    belowcaptionskip=0pt,
    breaklines=true,
    %frame=L,
    %xleftmargin=\parindent,
    language=C++,
    showstringspaces=false,
    basicstyle=\small\ttfamily,
    keywordstyle=\bfseries\color{green!40!black},
    commentstyle=\itshape\color{purple!40!black},
    identifierstyle=\color{blue},
    stringstyle=\color{orange},
}
\lstset{escapechar=@,style=customcpp}

% ------------------------------------------------------------%
% 设置封面
\renewcommand*{\maketitle}
{
    \begin{titlepage}
        %        \newgeometry{margin = 0.5in}
        \newgeometry{top = 7cm}
        \parindent=0pt
        %        \includegraphics[width=\linewidth]{cover.png}  % ---------此处将cover.png换为封面图片
        \vfill
        \begin{center}
            \parbox{0.618\textwidth}{
                \hfill {\bfseries \Huge \thetitle} \\[0.6pt]  
                \rule{0.618\textwidth}{4pt} \\ 
            }
        \end{center}
        \vfill
        \begin{center}
            \parbox{0.618\textwidth}{
                \hfill\Large
                \kaishu 
                \begin{tabular}{r|}
                    作者：\theauthor \\ 
                    时间：\thedate \\
                \end{tabular}
            }
        \end{center}
        \vfill
        \begin{center}
            \parbox[t]{0.7\textwidth}{\centering \kaishu }
        \end{center}
        \vfill
    \end{titlepage}
}
% ------------------------------------------------------------%
% 设置目录格式，章节形式
\usepackage{titlesec, titletoc}
\usepackage{fancyhdr}
\usepackage{multicol}  % 双栏目录使用的包
\setcounter{tocdepth}{1}  % 设置目录的编号层级，3代表目录收录到subsubsection一级
\setcounter{secnumdepth}{3}  % 设置section的编号层级，3代表编号写到subsubsection一级
\linespread{1.2} 				
\fancyhf{}
\renewcommand{\headrule}{\hrule width\textwidth}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{1pt}
\fancypagestyle{plain}{\renewcommand{\headrulewidth}{0pt}\fancyhf{}\renewcommand{\headrule}{}}

\ctexset{
    part = {
        titleformat = \raggedright,
        name = {第,部分},
        number = \arabic{part}
    },
    chapter = {
        titleformat = \raggedright,
        name = {第,章},
        number = \arabic{chapter}
    }
}

\titlecontents{part} [0.5 cm]
{\vspace{0.7cm}\bf\Large}  % above code
{\contentslabel{2.0 em}}  % numbered-entry-format
{}  % numberless-entry-format
{\titlerule*[0.5pc]{$\cdot$} \bfseries\contentspage}  % filler-page-format
%[]  % below-code
\titlecontents{chapter} [2.0 cm] 
{\vspace{0.3cm}\bf} 
{\contentslabel{4.2 em}} 
{\hspace*{2.3em}} 
{\titlerule*[0.5pc]{$\cdot$} \bfseries\contentspage}
\titlecontents{section} [2.5 cm] 
{\bf} 
{\contentslabel{3.0 em}} 
{\hspace*{2.3em}} 
{\titlerule*[0.5pc]{$\cdot$} \bfseries\contentspage}
\titlecontents{subsection} [3.3 cm] 
{\bf} 
{\contentslabel{3.7 em}} 
{\hspace*{2.3em}} 
{\titlerule*[0.5pc]{$\cdot$} \bfseries\contentspage}
\titlecontents{subsubsection} [4.5 cm] 
{\bf} 
{\contentslabel{5.0 em}} 
{\hspace*{2.3em}} 
{\titlerule*[0.5pc]{$\cdot$} \bfseries\contentspage}
% 20241205 - paragraph和subparagraph不显示在目录中，所以格式也不用配置
%\titlecontents{paragraph} [5.0 cm] 
%{} 
%{\contentslabel{5.0 em}} 
%{} % {\hspace*{2.3em}} 
%{\titlerule*[0.5pc]{$\cdot$} \bfseries\contentspage}
%\titlecontents{subparagraph} [5.6 cm] 
%{} 
%{\contentslabel{5.0 em}} 
%{} % {\hspace*{2.3em}} 
%{\titlerule*[0.5pc]{$\cdot$} \bfseries\contentspage}

\titleformat{\section}[frame]{\normalfont}{\footnotesize \enspace \large {\S \,\thesection}\enspace}{6pt}{\Large\filcenter \bf \kaishu }
\titleformat{\subsection}[hang]{\bfseries}{\large\bfseries\thesubsection\enspace}{1pt}{\large\bfseries\filright}
\titleformat{\subsubsection}[hang]{\bfseries}{\large\bfseries\thesubsubsection\enspace}{1pt}{\large\bfseries\filright}

% 生成章节内目录
\usepackage{minitoc}  % 章节内目录所需要的包
\dominitoc  % 初始化minitoc包
%\mtcsetrules{minitoc}{off} % 关闭小目录的上下划线
\mtcsettitle{minitoc}{章节目录} % 自定义小目录标题
\mtcsetdepth{minitoc}{3}  % 3表示显示到subsubsection一级